package com.umakr.demo.controller;


import com.umakr.demo.model.Combobox;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yangliu on 2017/8/12.
 */
@RequestMapping("/day11")
@Controller
public class Controller11 {

    @RequestMapping("/index1")
    public String index(){
        return "/day11/from";
    }

    @RequestMapping("/datagrid")
    @ResponseBody
    public List show(){
        List<Combobox.pojo> list = new ArrayList<>();
        Combobox.pojo p = new Combobox.pojo();
        p.setProductid("FI-SW-01");
        p.setUnitcost("10.00");
        p.setStatus("P");
        p.setListprice("36.50");
        p.setAttr1("Large");
        p.setItemid("EST-1");
        list.add(p);
        Combobox.pojo p2 = new Combobox.pojo();
        p2.setProductid("FI-SW-02");
        p2.setUnitcost("11.00");
        p2.setStatus("P");
        p2.setListprice("35.30");
        p2.setAttr1("Large2");
        p2.setItemid("EST-12");
        list.add(p2);
        Combobox.pojo p3 = new Combobox.pojo();
        p3.setProductid("FI-SW-03");
        p3.setUnitcost("13.00");
        p3.setStatus("P");
        p3.setListprice("35.30");
        p3.setAttr1("Large3");
        p3.setItemid("EST-13");
        list.add(p3);
        return list;
    }

    @RequestMapping("/index2")
    public String index2(){
        return "/day11/Tree_ajax";

    }

    @RequestMapping("/tree")
    @ResponseBody
    public List show2(){
        List<Combobox.treedemo> list_zitree1 = new ArrayList<>();
        Combobox.treedemo z1 = new Combobox.treedemo("111", "Friend");
        Combobox.treedemo z2 = new Combobox.treedemo("112", "Wife");
        Combobox.treedemo z3 = new Combobox.treedemo("113", "Company");
        list_zitree1.add(z1);
        list_zitree1.add(z2);
        list_zitree1.add(z3);

        List<Combobox.treedemo> list_zitree2 = new ArrayList<>();
        Combobox.treedemo z4 = new Combobox.treedemo("122","Java");
        Combobox.treedemo z5 = new Combobox.treedemo("121","Intel");
        Combobox.treedemo z6 = new Combobox.treedemo("123","Microsoft Office");
        Combobox.treedemo z7 = new Combobox.treedemo("124","Games");
        list_zitree2.add(z4);
        list_zitree2.add(z5);
        list_zitree2.add(z6);
        list_zitree2.add(z7);

        List<Combobox.treedemo> list_zitree3 = new ArrayList<>();
        Combobox.treedemo z11 = new Combobox.treedemo("11","Photos",list_zitree1);
        Combobox.treedemo z12 = new Combobox.treedemo("12","Program Files",list_zitree2);
        list_zitree3.add(z11);
        list_zitree3.add(z12);

        List<Combobox.treedemo> list = new ArrayList<>();
        Combobox.treedemo node = new Combobox.treedemo("1","My Documents",list_zitree3);
        list.add(node);
        return list;
    }

    @RequestMapping("/form")
    @ResponseBody
    public Map form(String name,String password){
        Map<String,String> map =new HashMap<>();
        map.put("name",name);
        map.put("password",password);

        return map;
    }
}
